package com.rahms.server.controller;

import com.rahms.common.result.R;
import com.rahms.pojo.entity.SystemMessage;
import com.rahms.server.service.SystemMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统消息控制器
 */
@RestController
@RequestMapping("/system-message")
public class SystemMessageController {
    
    @Autowired
    private SystemMessageService systemMessageService;
    
    /**
     * 获取接收者的系统消息列表
     */
    @GetMapping("/list")
    public R<List<SystemMessage>> getMessagesByRecipientId(@RequestParam Long recipientId,
                                                        @RequestParam(required = false) String msgType,
                                                        @RequestParam(required = false) Integer isRead) {
        List<SystemMessage> list = systemMessageService.getMessagesByRecipientId(recipientId, msgType, isRead);
        return R.success(list);
    }
    
    /**
     * 发送系统消息
     */
    @PostMapping("/send")
    public R<Boolean> sendSystemMessage(@RequestBody SystemMessage message) {
        boolean result = systemMessageService.sendSystemMessage(message);
        return result ? R.success(true) : R.error("发送失败");
    }
    
    /**
     * 标记消息为已读
     */
    @PostMapping("/mark-read")
    public R<Boolean> markMessageAsRead(@RequestParam Long messageId) {
        boolean result = systemMessageService.markMessageAsRead(messageId);
        return result ? R.success(true) : R.error("标记失败");
    }
}